import { request } from ".";
import type { RESPONSE } from "../types/base";
import type { LoginForm, RegisterForm, User } from "../types/userType";

export const reqRegister = (from: RegisterForm) =>
    request.post<null, RESPONSE<User>>("/api/user/register", from)


export const reqLogin = (from: LoginForm) =>
    request.post<null, RESPONSE<User> & { token?: string }>("/api/user/login", from)

export const reqWhoAmI = () =>
    request.get<null, RESPONSE<User>>("/api/user/whoami")

export const reqCheckPwd = (username: string, password: string) =>
    request.post<null, RESPONSE>("/api/user/checkpwd", {
        username,
        password
    })

export const reqUpdatePwd =(username:string,password:string)=>{
    request.post<null,RESPONSE>("/api/user/updatePwd",{username,password})
}

export const reqUpdateUser = (username:string,obj:object) =>
    request.put<null,RESPONSE<User>>(`/api/user/${username}`,obj)
